<?php

require_once '../inc/init.php';
chkpurview('daily_online_time');

$action = isset($_GET['action']) ? $_GET['action'] : 'server';

$start = microtime(true);
$today = date('Ymd');
$yesterday = date('Ymd',strtotime('-1 days',time()));
$firstday=date("Ym01");		//当月的第一天

if($action == 'server')			//服务器详情
{
	$servers = getServers();
	$servers_info = array();
	foreach($servers as $k=>$v)
	{
		$server_id = $v['id'];
		$sql = "SELECT server_id,total_users, total_players,total_players
					FROM tb_statistics_pay AS sp ";
		$servers_info[$k] = $db->getRow($sql);
		
		$servers_info[$k]['server_name'] = $v['server'];
		$servers_info[$k]['server_id'] = $server_id;
		$servers_info[$k]['total_users'] = number_format($servers_info[$k]['total_users']);
		$servers_info[$k]['total_players'] = number_format($servers_info[$k]['total_players']);
		$servers_info[$k]['total_player_loss_rate'] = round($servers_info[$k]['total_players']/$servers_info[$k]['total_users'],2);
		$servers_info[$k]['total_old_users'] = number_format($servers_info[$k]['total_old_users']);
		$servers_info[$k]['day_qpoint'] = number_format($servers_info[$k]['day_qpoint']/100,2);
		$servers_info[$k]['month_qpoint'] = number_format($servers_info[$k]['month_qpoint']/100,2);
		$servers_info[$k]['onine_max'] = number_format($servers_info[$k]['onine_max']);
		$servers_info[$k]['online_avg'] = number_format($servers_info[$k]['online_avg']);
		
		//循环获取每个服当前的在线玩家数
		$url =  'http://' . $v['innerip1'] .'/backend/task/online_users_out.php';
		$contents = makeRequest($url);
		$online_list_temp = xml2array($contents);
		if(empty($online_list_temp))
		{
			continue;
		}
		$servers_info[$k]['online_users'] = $online_list_temp[0];			
		
	}
	
	$T->assign('servers_info',$servers_info);
}
else if($action == 'online')
{
	$servers = getServers();
	$online_users = 0;
	foreach($servers as  $k=>$v)
	{
		//循环获取每个服当前的在线玩家数
		$url =  'http://' . $v['innerip1'] .'/backend/task/online_users_out.php';
		$contents = makeRequest($url);
		$online_list_temp = xml2array($contents);
		if(empty($online_list_temp))
		{
			continue;
		}
		$online_users += $online_list_temp[0];		
	}
	echo $online_users;
	exit;
}

$end = microtime(true);
$last = $end-$start;
$T->assign('last',$last);

$T->assign('action',$action);
$T->display('stay_rate_compare.html');



